package com.bluemsun.naturallanguageprocessing.exceptionHandler;

import com.bluemsun.naturallanguageprocessing.common.ServerResponse;
import com.bluemsun.naturallanguageprocessing.exception.feedback.AddFeedbackException;
import com.bluemsun.naturallanguageprocessing.exception.feedback.DeleteFeedbackException;
import com.bluemsun.naturallanguageprocessing.exception.feedback.GetFeedbackException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author :hucl
 * @describe :反馈异常全局处理类
 */
@RestControllerAdvice
public class FeedbackExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(FeedbackExceptionHandler.class);

    @ExceptionHandler(AddFeedbackException.class)
    public ServerResponse addFeedbackException(AddFeedbackException e){
        logger.error("反馈持久化到数据库出错："+e.getMessage());
        return ServerResponse.createByErrorMessage("对不起，预料之外的错误，反馈失败");
    }

    @ExceptionHandler(GetFeedbackException.class)
    public ServerResponse getFeedbackException(GetFeedbackException e){
        logger.error("获取用户反馈异常："+e.getMessage());
        return ServerResponse.createByErrorMessage("对不起，预料之外的错误，获取反馈信息失败");
    }

    @ExceptionHandler(DeleteFeedbackException.class)
    public ServerResponse deleteFeedbackException(DeleteFeedbackException e){
        logger.error("删除用户反馈异常："+e.getMessage());
        return ServerResponse.createByErrorMessage("对不起，预料之外的错误，删除反馈信息失败");
    }
}
